home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_dev-disk / egsdemos / egsexamples / other / eyes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  5.7 KB  |  274 lines

  1. /*
  2. *
  3. *  $ FILE     : eyes.c
  4. *  $ VERSION  : 1
  5. *  $ REVISION : 1
  6. *  $ DATE     : 08-Dec-93 18:52
  7. *  $
  8. *  $ Author   : mvk
  9. *  $
  10. *
  11. *
  12. *  Just EYES.
  13. *
  14. *
  15. */
  16.  
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19.  
  20. #include <exec/types.h>
  21. #include <proto/exec.h>
  22. #include <proto/dos.h>
  23. #include <egs/egs.h>
  24. #include <egs/egsintuigfx.h>
  25. #include <egs/egsintui.h>
  26. #include <egs/egslayers.h>
  27. #include <egs/egsgfx.h>
  28.  
  29.  
  30. #include <egs/proto/egs.h>
  31. #include <egs/proto/egsintui.h>
  32. #include <egs/proto/egslayers.h>
  33. #include <egs/proto/egsgfx.h>
  34.  
  35.  
  36. struct EI_NewWindow newWindow =
  37. {
  38.   200, 0, 300, 150,
  39.   300, 150, 300, 150,
  40.   NULL,
  41.   EI_WINDOWCLOSE+EI_WINDOWBACK+EI_WINDOWDRAG,
  42.   NULL,                                      /* GadgetPtr */
  43.   "Eyes",
  44.   EI_SIMPLE_REFRESH,
  45.   EI_iCLOSEWINDOW+EI_iREFRESHWINDOW
  46.   /* Der Rest ist egal */
  47.   };
  48.  
  49.  
  50.  
  51. EI_WindowPtr win;
  52. EG_RastPortPtr rast;
  53. E_EBitMapPtr ras;
  54. struct EG_AreaInfo info;
  55. EG_Polygon buffer[40];
  56. WORD midX, midY;
  57. WORD radius;
  58. WORD prad;
  59. WORD rmax, xmax, ymax;
  60.  
  61. struct Library *EGSIntuiBase;
  62. struct Library *EGSLayersBase;
  63. struct Library *EGSGfxBase;
  64. struct Library *EGSBase;
  65.  
  66. void DrawEyes (void)
  67. {
  68.   rast->APen = win->WinColors.Dark;
  69.   EG_AreaCircle (rast, (WORD)(midX-radius), (WORD)(midY),(WORD)(radius-4));
  70.   EG_AreaCircle (rast, (WORD)(midX+radius), (WORD)(midY), (WORD)(radius-4));
  71.  
  72.   rast->APen = win->WinColors.Light;
  73.  
  74.   EG_AreaCircle(rast, (WORD)(midX-radius), (WORD)(midY),(WORD)(radius-6));
  75.   EG_AreaCircle (rast,(WORD)(midX+radius), (WORD)(midY), (WORD)(radius-6));
  76. }
  77.  
  78.  
  79. void DrawPupill (WORD x, WORD y)
  80. {
  81.   rast->APen = win->WinColors.Dark;
  82.   EG_AreaCircle (rast, (WORD)x, (WORD)y, (WORD)prad);
  83.   rast->APen = win->WinColors.Light;
  84.   EG_AreaCircle (rast, (WORD)(x-prad / 2), (WORD)(y-prad / 2), (WORD)(prad / 4));
  85.  
  86. }
  87.  
  88.  
  89. void RedrawPupill (WORD x, WORD y)
  90. {
  91.   rast->APen = win->WinColors.Light;
  92.   EG_AreaCircle (rast, (WORD)x, (WORD)y, (WORD)prad);
  93. }
  94.  
  95.  
  96. WORD py1, py2, px1, px2;
  97. WORD oy1, oy2, ox1, ox2;
  98. WORD oldX, oldY;
  99.  
  100.  
  101. WORD SQR (LONG x)
  102. {
  103.   WORD h1, h2, h3;
  104.  
  105.   if ((x<0) || (x>2000*2000))
  106.     x = 1;
  107.   h1 = 1;
  108.   h2 = x / 2;
  109.   while ((h1*h1>x) || (h1+1)*(h1+1)<x)
  110.     {
  111.     h3 = (h1+h2) / 2;
  112.     h2 = h1;
  113.     h1 = x / h3;    /* oder h3 / x ??? */
  114.     }
  115.   return h1;
  116. }
  117.  
  118.  
  119.  
  120. void CalcPupills (WORD dx, WORD dy)
  121. {
  122.   py1 = midY + ( (dy*(radius-prad-6)) / rmax);
  123.   px1 = midX + ( ((dx+radius)*(radius-prad-6)) / rmax) - radius;
  124.   py2 = midY + ( (dy*(radius-prad-6)) / rmax);
  125.   px2 = midX + ( ((dx-radius)*(radius-prad-6)) / rmax) + radius;
  126. }
  127.  
  128.  
  129. void RedrawPupills (void)
  130. {
  131.   if ((oldX!=win->WScreen->EScreen->MouseX) ||
  132.      (oldY!=win->WScreen->EScreen->MouseY))
  133.     {
  134.     oldX = win->WScreen->EScreen->MouseX;
  135.     oldY = win->WScreen->EScreen->MouseY;
  136.     CalcPupills ((WORD)(oldX-(win->LeftEdge+midX)),(WORD)(oldY-(win->TopEdge+midY)));
  137.  
  138.     EL_LockLayer (win->WLayer);
  139.     E_MouseOff (win->WScreen->EScreen);
  140.     RedrawPupill (ox1, oy1);
  141.     DrawPupill (px1, py1);
  142.     ox1 = px1;
  143.     oy1 = py1;
  144.     RedrawPupill (ox2, oy2);
  145.     DrawPupill (px2, py2);
  146.     ox2 = px2;
  147.     oy2 = py2;
  148.     E_MouseOn (win->WScreen->EScreen);
  149.     EL_UnlockLayer (win->WLayer);
  150.     }
  151. }
  152.  
  153.  
  154.  
  155. void ReDraw (void)
  156. {
  157.   DrawEyes ();
  158.   DrawPupill (px1, py1);   ox1 = px1;   oy1 = py1;
  159.   DrawPupill (px2, py2);   ox2 = px2;   oy2 = py2;
  160. }
  161.  
  162.  
  163.  
  164. void Crash (char *string)
  165. {
  166.   if (win!=NULL)
  167.     {
  168.     EI_CloseWindow (win);
  169.     win = NULL;
  170.     }
  171.   if (ras!=NULL)
  172.     E_DisposeBitMap (ras);
  173.   if (EGSIntuiBase)
  174.     CloseLibrary (EGSIntuiBase);
  175.   if (EGSGfxBase)
  176.     CloseLibrary (EGSGfxBase);
  177.   if (EGSLayersBase)
  178.     CloseLibrary (EGSLayersBase);
  179.   if (EGSBase)
  180.     CloseLibrary (EGSBase);
  181.   if (string != NULL)
  182.     {
  183.     printf ("%s\n", string);
  184.     exit (20L);
  185.     }
  186.   exit (0L);
  187. }
  188.  
  189.  
  190.  
  191. EI_EIntuiMsgPtr msg;
  192. BOOL done;
  193. extern float sqrt (float f);
  194.  
  195. void main (void)
  196. {
  197.   /* Öffne die Bibliotheken */
  198.  
  199.   EGSBase = (APTR) OpenLibrary ("egs.library", 0);
  200.   if (NULL == EGSBase)
  201.     Crash ("Konnte EGS.library nicht öffnen");
  202.  
  203.   EGSIntuiBase = (APTR) OpenLibrary ("egsintui.library", 0);
  204.   if (NULL == EGSIntuiBase)
  205.     Crash ("Konnte EGSIntui.library nicht öffnen");
  206.  
  207.   EGSGfxBase = (APTR) OpenLibrary ("egsgfx.library", 0);
  208.   if (NULL == EGSGfxBase)
  209.     Crash ("Konnte EGSGfx.library nicht öffnen");
  210.  
  211.   EGSLayersBase = (APTR) OpenLibrary ("egslayers.library", 0);
  212.   if (NULL == EGSLayersBase)
  213.     Crash ("Konnte EGSLayers.library nicht öffnen");
  214.  
  215.   win = NULL;
  216.   win = EI_OpenWindow (&newWindow);
  217.   if (win == NULL)
  218.     Crash ("Konnte Fenster nicht öffnen");
  219.  
  220.   rast = win->RPort;
  221.   midX = win->BorderLeft + win->Width / 2;
  222.   midY = win->BorderTop + win->Height / 2;
  223.   radius = win->Height / 2;
  224.   prad = (radius*2) / 5;
  225.  
  226.   rmax = (WORD) (sqrt( (float) (( (win->WScreen->Width-radius)*
  227.   (win->WScreen->Width-radius)) +
  228.   ((win->WScreen->Height-radius)*
  229.   (win->WScreen->Height-radius) )) ) );
  230.  
  231.   printf ("Win->Width %d",win->Width);
  232.   printf ("Win->Width %d",win->Height);
  233.  
  234.   ras = E_AllocBitMap (win->Width, win->Height, (UWORD)1, 0, 0,0);
  235.   if (ras == NULL)
  236.     Crash ("Konnte EBitMap nicht belegen");
  237.   else
  238.     {
  239.     rast->TmpRas = ras;
  240.     rast->AreaInfo = EG_InitArea (&info, &buffer[0], (WORD)500);
  241.     oldX = win->WScreen->EScreen->MouseX;
  242.     oldY = win->WScreen->EScreen->MouseY;
  243.     CalcPupills ((WORD)(oldX-(win->LeftEdge+midX)),
  244.     (WORD)(oldY-(win->TopEdge+midY)));
  245.     ReDraw ();
  246.     done = FALSE;
  247.     do {
  248.       Delay (10);
  249.       msg = (EI_EIntuiMsgPtr)GetMsg (win->UserPort);
  250.       while (msg!=NULL)
  251.  {
  252.  if (EI_iREFRESHWINDOW & msg->Class)
  253.    {
  254.    if (EI_BeginRefresh (win, (LONG)msg->IAddress))
  255.      {
  256.      ReDraw ();
  257.      EI_EndRefresh (win, TRUE);
  258.      }
  259.    }
  260.  if (EI_iCLOSEWINDOW & msg->Class)
  261.    done = TRUE;
  262.  ReplyMsg ((struct Message *)msg);
  263.  
  264.  msg = (EI_EIntuiMsgPtr)GetMsg (win->UserPort);
  265.  }
  266.       RedrawPupills ();
  267.       } while (! done);
  268.     }
  269.  
  270.   /* Beende das Programm */
  271.   Crash (NULL);
  272. }
  273.  
  274.